package com.neusoft.neuiotms.dcam.fixed.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.neusoft.neuiotms.dcam.constant.DCAMConsts;
import com.neusoft.neuiotms.micro.notice.NoticeMicroService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class SendingMessage {
    @Autowired
    private NoticeMicroService systemNoticeMicroService;

    /**
     * @param notice 示例如下
     */
    public void SendMsgToNotice(final String notice) {
        this.systemNoticeMicroService.createNotification(notice);
        SendingMessage.log.info("发送的消息内容是： " + notice);
    }

    public void SendImportResultToNotice(final String title, final String username, final String content) {
        final JSONObject obj = new JSONObject();
        final String[] type = {DCAMConsts.INFORM_TYPE_NOTICE, DCAMConsts.INFORM_TYPE_MAIL };
        obj.put("title", title);
        obj.put("type", type);
        obj.put("appCode", "dcam");

        final JSONObject sys = new JSONObject();
        sys.put("content", content);
        sys.put("noticeType", "基本通知");
        final String[] users = {username };
        sys.put("users", users);

        obj.put("system", sys);
        //        System.out.println(sys);
        this.SendMsgToNotice(obj.toString());
    }
}
